// const baseUrl = 'http://localhost:18080/biz/front'; 
// const baseUrl = 'http://shirlly46.free.idcfengye.com/biz/front';
const baseUrl = 'https://car.cofcooil.com:38080/biz/front';

const version = '/1.2'

const formatTime = date => { 
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const $http = {
  request: function(params) {
    params.url = baseUrl + version + params.url;
    const phone = wx.getStorageSync('phone');
    params.header = {
      'phone': phone,
      'isWX': 'true'
    }
    wx.request(params);
  },
  get: function(params) {
    params.method = 'get';
    this.request(params)
  },
  post: function(params) {
    params.method = 'post';
    this.request(params)
  }
}

module.exports = {
  formatTime, $http
}
